<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>登录/注册</title>
    <!-- 导入 LayUI 的样式 -->
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <!-- 自己的样式表 -->
    <link rel="stylesheet" href="/css/login.css">
    <style>
        .title {
            text-align: center;
            font-size: 20px;
            padding: 10px 0;
            color: #27bde8;
            font-weight: bold;
        }
    </style>
</head>

<body>

    <!-- 登录注册区域 -->
    <div class="loginAndReg">
        <div class="title">注册用户</div>
        <!-- 注册的div -->
        <div class="reg-box">
            <!-- 注册的表单 -->
            <form class="layui-form" id="form_reg" onsubmit="return setDatasubmit()" action="/registerPost"
                method="post">
                <!-- 用户名 -->
                <div class="layui-form-item">
                    <i class="layui-icon layui-icon-username"></i>
                    <input type="text" id="username" name="username" placeholder="请输入用户名"" class=" layui-input" />
                </div>
                <!-- 密码 -->
                <div class="layui-form-item">
                    <i class="layui-icon layui-icon-password"></i>
                    <input type="password" name="password" id="password" pwd" placeholder="请输入密码" class="layui-input" />
                </div>
                <!-- 密码确认框 -->
                <div class="layui-form-item">
                    <i class="layui-icon layui-icon-password"></i>
                    <input type="password" name="password2" id="password2" placeholder="再次确认密码" class="layui-input" />
                </div>
                <!-- 注册按钮 -->
                <div class="layui-form-item">
                    <!-- 注意：表单提交按钮和普通按钮的区别，就是 lay-submit 属性 -->
                    <button type="submit" class="layui-btn layui-btn-fluid layui-btn-normal">注册</button>
                </div>
                <div class="layui-form-item links">
                    <a href="/login" id="link_login">去登录</a>
                </div>
            </form>
        </div>
    </div>
    <script>
        function setDatasubmit() {
            console.log("提交请求");
            // 表单验证
            var username = document.getElementById("username").value;
            var password = document.getElementById("password").value;
            var password2 = document.getElementById("password2").value;
            var reg_username = /^[A-Za-z0-9\u4e00-\u9fa5]{2,10}$/;
            var reg_password = /^[a-zA-Z0-9]\w{5,17}$/
            if (!reg_username.test(username) || !reg_password.test(password) || password2 != password) {
                alert("请输入正确数据");
                return false;
            }

            return true;
        }

    </script>
</body>

</html>